import { debug } from 'webpack'
import { AppModel } from '../../../../model/AppModel'
import { createPartMenu, createVarMenu } from '../BlockPackage'

declare var Vue : any


export default {

    category: Blockly.Categories.bepart ,
    
    color: [
        Blockly.Colours.bepart.primary,
        Blockly.Colours.bepart.secondary,
        Blockly.Colours.bepart.tertiary
    ] ,

    previousStatement: true ,
    nextStatement: true ,
    inputsInline: false,

    init(model:Model, scratch3:any) {
        this.appendDummyInput()
            .appendField("UDP广播数据")
            .appendField(createVarMenu(scratch3), 'var')
            .appendField("到端口")
        this.appendValueInput("port")
    } ,

    run (args: any, util: any, runtime: any, model: AppModel) {
    } ,

    coder: {
        JavaScript(block: any, coder: any, model: AppModel) {
            let indent = coder.indentString()
            let varname = block.getFieldValue('var')
            let port = coder.valueToCode(block, "port", coder.ORDER_ASSIGNMENT)||0
            return `${indent}socks.udp.broadcase(null, ${port}, be.var["${varname}"])\n`
        }
    }
}
